package com.hcinfos.gsoo.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.hcinfos.gsoo.R;

public class WebViewActivity extends Activity implements OnClickListener {

	private ImageView left_iv;
	private WebView webView;
	private ProgressBar loading_pb;

	@SuppressLint("SetJavaScriptEnabled")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_webview);

		webView = (WebView) findViewById(R.id.webView);
		left_iv = (ImageView) findViewById(R.id.left_iv);
		left_iv.setOnClickListener(this);

		loading_pb = (ProgressBar) findViewById(R.id.loading_pb);

		String url = getIntent().getStringExtra("url");
		WebSettings webSetting = webView.getSettings();
		webSetting.setJavaScriptEnabled(true);
		webSetting.setUseWideViewPort(true);
		webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
		webView.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}

			@Override
			public void onPageFinished(WebView view, String url) {

				loading_pb.setVisibility(View.GONE);
				super.onPageFinished(view, url);
			}
		});
		webView.loadUrl(url);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.left_iv:
			finish();
			break;
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			finish();
		}
		return super.onKeyDown(keyCode, event);
	}

}
